feat(vm): IO — byte/char reads, gets limit/chomp, pread/pwrite, half-close - #347
Merged
Conversation
…close
Horodate: 2026-08-10 10:12 CEST
Advance the IO / File / StringIO read+write surface toward MRI 3.4/4.0 on
the existing buffer-backed IOObj model.
Shared (IO, File, StringIO):
- getbyte / readbyte / readchar (EOFError at EOF)
- ungetbyte / ungetc (Integer + String pushback, nil no-op, TypeError)
- each_byte / each (return self)
- sysread (len + output buffer, EOFError, negative -> ArgumentError) / syswrite
- gets/readline/readlines/each_line now honour (sep, limit, chomp:)
- #lineno / #lineno= (advanced by each successful line read)
- close_read / close_write / closed_read? / closed_write?
(both halves shut -> fully closed; write flushes)
- readable/writable guards: IOError "not opened for reading|writing"
IO + File only (not StringIO):
- pread / pwrite (absolute offset, cursor untouched; Errno::EINVAL,
EOFError, FrozenError buffer)
- sysseek (returns resulting position)
- binmode? / autoclose? / autoclose= / fdatasync
Deferred: fileno (no real fd in the buffer model), non-duplex close raise,
IO.select threaded corners.
Verification:
- go test ./internal/vm/ -run TestIODescriptors: PASS
- new code 100% incl error branches (per-func cover)
- gofmt + go vet clean; no prelude.rb change
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Horodate: 2026-08-10 10:34 CEST
readlines / each_line / each / IO.foreach / IO.readlines now raise
ArgumentError "invalid limit: 0 for <meth>" for an explicit 0 byte limit,
matching MRI. A 0-byte line never advances the cursor, so the earlier
limit support looped forever on core/io/{each_line,foreach}_spec. A single
#gets(0) still returns "" (single call, no loop). foreach/readlines class
methods also gained (sep, limit) pass-through.
Verification:
- core/io/{each_line,foreach,readlines}_spec + stringio specs now
complete (were hanging) with higher pass counts
- go test ./... PASS; whole-package cover gate: only tolerated partials
(registerIOClassMethods now 100%)
- gofmt + go vet clean
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Horodate: 2026-08-10 10:40 CEST Measured 12517 passing after the IO read/write surface work (N-30 margin for the known ratchet infra-flake). Keep the higher FLOOR on any merge conflict with a concurrent File/Dir PR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
# Conflicts: # scripts/conformance/rubyspec/FLOOR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Horodate: 2026-08-10 10:41 CEST
Advances the
IO/File(as IO) /StringIOread+write surface toward MRI 3.4/4.0 on the existing buffer-backedIOObjmodel, with per-branch tests and a ruby/spec ratchet bump.What's implemented
Shared (IO, File, StringIO):
getbyte/readbyte/readchar(EOFErrorat EOF)ungetbyte/ungetc(Integer + String pushback,nilno-op,TypeError)each_byte/each(return self)sysread(length + output-buffer arg,EOFError, negative →ArgumentError) /syswritegets/readline/readlines/each_linenow honour(sep, limit, chomp:), with universal-newline chomp#lineno/#lineno=(advanced by each successful line read)close_read/close_write/closed_read?/closed_write?(both halves shut ⇒ fully closed;close_writeflushes)IOError "not opened for reading|writing","closed stream"IO + File only (not StringIO):
pread/pwrite(absolute offset, cursor untouched;Errno::EINVAL,EOFError,FrozenErroron a frozen buffer)sysseek(returns the resulting position)binmode?/autoclose?/autoclose=/fdatasyncCorrectness fix:
readlines/each_line/each/IO.foreach/IO.readlinesnow raiseArgumentError "invalid limit: 0 for <meth>"for an explicit 0 limit (a 0-byte line never advances the cursor — the limit support otherwise looped forever oncore/io/{each_line,foreach}_spec). A single#gets(0)still returns"". Theforeach/readlinesclass methods also gained(sep, limit)pass-through.Deferred
#fileno(no real fd in the buffer-backed model; StringIO returns nil, IO an Integer — fabricating an fd was judged worse than omitting)close_read/close_writeraise ("closing non-duplex IO")IO.selectblocking/threaded corners, tty/ioctlVerification
go test ./...: PASS (8 packages)registerIOClassMethodsreached 100%)gofmt+go vetclean; noprelude.rbchangecore/io/{each_line,foreach,readlines}+ StringIO specs that previously hung now complete with higher pass counts.🤖 Generated with Claude Code